/*********************************************************************************
 *      Copyright:  (C) 2021 litupei<lismilepei@163.com>
 *                  All rights reserved.
 *
 *       Filename:  prj_iniparser.h
 *    Description:  This file is prj_iniparser.h
 *                 
 *        Version:  1.0.0(2021年08月08日)
 *         Author:  litupei <lismilepei@163.com>
 *      ChangeLog:  1, Release initial version on "2021年08月08日 23时23分47秒"
 *                 
 ********************************************************************************/

#include "prj_iniparser.h"

int ini_mqttmsg(const char *PATH_ini, mqtt_cxt_t *mqtt)
{
	dictionary  *ini = NULL;

	ini = iniparser_load(PATH_ini);
	if(ini == NULL)
	{
		printf("iniparser load failure : %s! \n", strerror(errno));
        return -1;
	}
	printf("iniparser load successfully! \n");

	strncpy(mqtt->username, iniparser_getstring(ini, "user_passwd:username", NULL), sizeof(mqtt->username));

	strncpy(mqtt->pub_password, iniparser_getstring(ini, "user_passwd:pub_password", NULL), sizeof(mqtt->pub_password));

	strncpy(mqtt->host, iniparser_getstring(ini, "aliy_addr:host", NULL), sizeof(mqtt->host));

	strncpy(mqtt->pub_client, iniparser_getstring(ini, "ClientID:pub_client", NULL), sizeof(mqtt->pub_client));

	mqtt->port = iniparser_getint(ini, "aliy_addr:port", -1);

	mqtt->keepalive = iniparser_getint(ini, "Keep_alive:keepalive", -1);

	strncpy(mqtt->pub_topic, iniparser_getstring(ini, "topic:pub_topic", NULL), sizeof(mqtt->pub_topic));	

	strncpy(mqtt->sub_topic, iniparser_getstring(ini, "topic:sub_topic", NULL), sizeof(mqtt->sub_topic));	

	strncpy(mqtt->sub_password, iniparser_getstring(ini, "user_passwd:sub_password", NULL), sizeof(mqtt->sub_topic));	

	strncpy(mqtt->sub_client, iniparser_getstring(ini, "ClientID:sub_client", NULL), sizeof(mqtt->sub_client));	

	strncpy(mqtt->ZLOG_CONF_PATH, iniparser_getstring(ini, "zlog_path:zlog_file", NULL), sizeof(mqtt->ZLOG_CONF_PATH));	

	iniparser_freedict(ini);

	return 0;
}
